<template>
	<view class="container">
		<view class="titles">输入以下数据，再点击计算</view>
		<view class="item">
			<view class="name">最新落槌价</view>
			<view class="input-box">
				<view class="input">
					<input type="number" placeholder="请输入最新落槌价" placeholder-class="placeholder" v-model="hammerPrice" />
				</view>
				<text>元</text>
			</view>
		</view>
		<view class="item">
			<view class="name">拍价递增比</view>
			<view class="input-box">
				<view class="input">
					<input type="number" placeholder="请输入递增比例" placeholder-class="placeholder" v-model="proportion" />
					<view class="proportion">%</view>
				</view>
			</view>
		</view>
		<view class="item">
			<view class="name">提货价</view>
			<view class="input-box">
				<view class="input">
					<input type="number" placeholder="请输入提货价" placeholder-class="placeholder" v-model="pickUp" />
				</view>
				<text>元</text>
			</view>
		</view>
		<view class="actionEnd">
			<view class="name">距离结拍还有</view>
			<view class="days"> <text>{{days}}</text> 天</view>
		</view>
		<view class="calculate" @click="calculate">立即计算</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				hammerPrice: '', //落槌价
				proportion: '', //比例
				pickUp: '', //提货价
				days: 0, //天数
			};
		},
		methods: {
			validateInput() {
				if (!this.hammerPrice || !this.proportion || !this.pickUp) {
					uni.showToast({
						icon:'error',
						title:'请输入完整数据'
					})
					return false;
				}
				if (this.hammerPrice <= 0 || this.proportion <= 0 || this.pickUp <= 0) {
					uni.showToast({
						icon:'error',
						title:'输入值必须大于'
					})
					return false;
				}

				return true;
			},
			calculate() {
				// 数据验证
				if (!this.validateInput()) return;

				// 执行计算
				const base = 1 + (this.proportion / 100);
				const ratio = this.pickUp / this.hammerPrice;
				this.days = Math.floor(Math.log(ratio) / Math.log(base));
			}
		}
	}
</script>

<style lang="less">
	.container {
		padding: 54rpx 30rpx;

		.title {
			font-weight: 600;
			font-size: 30rpx;
			color: #333333;
		}

		.item {
			margin-top: 50rpx;

			.name {
				font-weight: 400;
				font-size: 30rpx;
				color: #666666;
			}

			.input-box {
				display: flex;
				align-items: center;
				margin-top: 36rpx;

				.input {
					border: 1rpx solid #DCDFE6;
					border-radius: 20rpx;
					height: 76rpx;
					padding: 0 15rpx;
					display: flex;
					align-items: center;
					flex: 1;
					position: relative;

					input {
						width: 100%;
					}
				}

				.placeholder {
					font-weight: 400;
					font-size: 26rpx;
					color: #C0C4CC;
				}

				.proportion {
					line-height: 76rpx;
					width: 117rpx;
					background: #F5F7FA;
					border-radius: 21rpx;
					text-align: center;
					position: absolute;
					right: 0;
					top: 0;
					font-weight: 400;
					font-size: 26rpx;
					color: #666666;
				}

				text {
					margin-left: 24rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
				}
			}
		}

		.actionEnd {
			text-align: center;
			margin-top: 50rpx;

			.name {
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
			}

			.days {
				display: flex;
				align-items: center;
				justify-content: center;
				margin-top: 53rpx;
				width: 144rpx;
				line-height: 80rpx;
				background: #2DD800;
				border-radius: 30rpx;
				text-align: center;
				margin: 53rpx auto;
				font-weight: 500;
				font-size: 30rpx;
				color: #FFFFFF;

				text {
					font-weight: 500;
					font-size: 44rpx;
					color: #FFFFFF;
					margin-right: 5rpx;
				}
			}
		}

		.calculate {
			width: 100%;
			line-height: 90rpx;
			text-align: center;
			background: #2DD800;
			border-radius: 50rpx;
			font-weight: 500;
			font-size: 32rpx;
			color: #FFFFFF;
		}

	}
</style>